<?php
/**
 *@author Connor <caokang@foxmail.com>
 *@todo
 *@link www.zeevin.com
 */


?>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquerydoubleselectmin.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.cookie.js"></script>
<script type="text/javascript">
var  df = function (id) {
  return "string" == typeof id ? document.getElementById(id) : id;
};

function addEventHandler(oTarget, sEventType, fnHandler) {
  if (oTarget.addEventListener) {
    oTarget.addEventListener(sEventType, fnHandler, false);
  } else if (oTarget.attachEvent) {
    oTarget.attachEvent("on" + sEventType, fnHandler);
  } else {
    oTarget["on" + sEventType] = fnHandler;
  }
};

var Class = {
  create: function() {
  return function() {
    this.initialize.apply(this, arguments);
  }
  }
}

var Extend = function(destination, source) {
  for (var property in source) {
    destination[property] = source[property];
  }
  return destination;
}

var DateSelector = Class.create();
DateSelector.prototype = {
  initialize: function(oYear, oMonth, oDay, options) {
  this.SelYear = df(oYear);//年选择对象
  this.SelMonth = df(oMonth);//月选择对象
  this.SelDay = df(oDay);//日选择对象
  
  this.SetOptions(options);
  
  var dt = new Date(), iMonth = parseInt(this.options.Month), iDay = parseInt(this.options.Day), iMinYear = parseInt(this.options.MinYear), iMaxYear = parseInt(this.options.MaxYear);
  
  this.Year = parseInt(this.options.Year) || dt.getFullYear()-18;
  this.Month = 1 <= iMonth && iMonth <= 12 ? iMonth : dt.getMonth() + 1;
  this.Day = iDay > 0 ? iDay : dt.getDate();
  this.MinYear = iMinYear && iMinYear < this.Year ? iMinYear : this.Year;
  this.MaxYear = iMaxYear && iMaxYear > this.Year ? iMaxYear : this.Year;
  this.onChange = this.options.onChange;
  
  //年设置
  this.SetSelect(this.SelYear, this.MinYear, this.MaxYear - this.MinYear + 1, this.Year - this.MinYear);
  //月设置
  this.SetSelect(this.SelMonth, 1, 12, this.Month - 1);
  //日设置
  this.SetDay();
  
  var oThis = this;
  //日期改变事件
  addEventHandler(this.SelYear, "change", function(){
    oThis.Year = oThis.SelYear.value; oThis.SetDay(); oThis.onChange();
  });
  addEventHandler(this.SelMonth, "change", function(){
    oThis.Month = oThis.SelMonth.value; oThis.SetDay(); oThis.onChange();
  });
  addEventHandler(this.SelDay, "change", function(){ oThis.Day = oThis.SelDay.value; oThis.onChange(); });
  },
  //设置默认属性
  SetOptions: function(options) {
  this.options = {//默认值
    Year:   0,//年
    Month:    0,//月
    Day:    0,//日
    MinYear:  0,//最小年份
    MaxYear:  0,//最大年份
    onChange: function(){}//日期改变时执行
  };
  Extend(this.options, options || {});
  },
  //日设置
  SetDay: function() {
  //取得月份天数
  var daysInMonth = new Date(this.Year, this.Month, 0).getDate();
  if (this.Day > daysInMonth) { this.Day = daysInMonth; };
  this.SetSelect(this.SelDay, 1, daysInMonth, this.Day - 1);
  },
  //select设置
  SetSelect: function(oSelect, iStart, iLength, iIndex) {
  //添加option
  oSelect.options.length = iLength;
  for (var i = 0; i < iLength; i++) { oSelect.options[i].text = oSelect.options[i].value = iStart + i; }
  //设置选中项
  oSelect.selectedIndex = iIndex;
  }
};
</script>
<!--main-->
<?php 
$form = $this->beginWidget('CActiveForm', array(
  'id'=>'user-regist',
  'enableAjaxValidation'=>true,
  'enableClientValidation'=>true,
  'focus'=>array($user,'email'),
  'clientOptions'=>array(
   'validateOnChange'=>true,
   'validateOnSubmit'=>true,
   )
  ));
  ?>

  <div class="warpper">
    <div class="container">
      <div class="register">
        <h1 class="tit">会员注册页</h1>
        <div class="register_box">
          <div class="base_infor">
            <div class="base_infor_top">
              <div class="left">
               <div class="nick">
                <label>邮&nbsp;&nbsp;&nbsp;&nbsp;箱：</label>
                <?php echo $form->textField($user,'email',array(),false);?><span class="color900" id='zee_email' style="color: rgb(51, 102, 0);display: none;" > √ </span>
                <p class="color900"><?php echo $form->error($user,'email');?></p>

              </div>
              <div class="nick">
                <label>密&nbsp;&nbsp;&nbsp;&nbsp;码：</label>
                <?php echo $form->passwordField($user,'password_tmp');?><span class="color900" id='zee_pwd' style="color: rgb(51, 102, 0);display: none;" > √ </span>
                <p class="color900"><?php echo $form->error($user,'password_tmp');?></p>
              </div>

              <div class="nick">
                <label>昵&nbsp;&nbsp;&nbsp;&nbsp;称：</label>
                <?php echo $form->textField($user,'nickname');?><span class="color900" id='zee_nick' style="color: rgb(51, 102, 0);display: none;" > √ </span>
                <p class="color900"><?php echo $form->error($user,'nickname');?></p>
              </div>
              <div class="domain">
                <label>域&nbsp;&nbsp;&nbsp;&nbsp;名：</label>
                <span>http://zcou.com/</span>
                <?php echo $form->textField($user,'subdomain');?><span class="color900" id='zee_sub' style="color: rgb(51, 102, 0);display: none;" > √ </span>
                <p class="color900"><?php echo $form->error($user,'subdomain');?></p>
              </div>
            </div>

          </div>
          <div class="base_infor_bottom">
            <ul>
              <li><span class="left"><strong>性&nbsp;&nbsp;&nbsp;&nbsp;别：</strong></span>
                <?php echo $form->radioButton($user, 'sex',array('value'=>User::SEX_MALE,'class'=>'seclect_sex','checked'=>'checked'));?>
                <span class="left" style="margin-right:10px;">男</span>
                <?php echo $form->radioButton($user, 'sex',array('value'=>User::SEX_FEMAL,'class'=>'seclect_sex'));?>
                <span class="left">女</span></li>
              </li>
              <li><span class="left"><strong>择友性别：</strong></span>
                <?php echo $form->radioButtonList($setting,'sex_tendency',User::getSex());?>
                <?php echo $form->radioButton($setting, 'sex_tendency',array('value'=>User::SEX_MALE,'class'=>'seclect_sex'));?>
                <span class="left" style="margin-right:10px;">男</span>
                <?php echo $form->radioButton($setting, 'sex_tendency',array('value'=>User::SEX_FEMAL,'class'=>'seclect_sex'));?>
                <span class="left" style="margin-right:10px;">女</span>
                <?php echo $form->radioButton($setting, 'sex_tendency',array('value'=>User::SEX_NONE,'class'=>'seclect_sex','checked'=>'checked'));?>
                <span class="left">不限</span>
              </li>
              <li><span class="left"><strong>生&nbsp;&nbsp;&nbsp;&nbsp;日：</strong></span>
                <select id="idYear"></select> 
                <select id="idMonth"></select> 
                <select id="idDay"></select> 
                <?php echo $form->hiddenField($user,'birth',array('id'=>"idShow"));?>
                <?php echo $form->error($user,'birth');?>
              </li>
              <li><span class="left"><strong>择友年龄：</strong></span>
                <?php echo $form->dropDownList($setting, 'age_start', Utils::genAgeSelect());?>
                <span class="left" style="margin-right:10px;">~</span>
                <?php echo $form->dropDownList($setting, 'age_end', array_reverse(Utils::genAgeSelect(),true));?>

              </li>
              <li><span class="left"><strong>城&nbsp;&nbsp;&nbsp;&nbsp;市：</strong></span>
                <?php //echo $form->textField($user,'province_id',array('value'=>12));?>
                <?php echo $form->dropDownList($user,'province_id',array('value'=>1374),array('class'=>'selected_province','id'=>'own_p'))?>
                <?php echo $form->dropDownList($user, 'city_id', array(),array('class'=>'selected_city','id'=>'own_c','style'=>'width:80px;'))?>
              </li>
              <li><span class="left"><strong>择友城市：</strong></span>
                <?php echo $form->dropDownList($setting,'province_id',array(),array('class'=>'province','id'=>'tendency_p'))?>
                <?php echo $form->dropDownList($setting, 'citys_tendency', array(),array('class'=>'city','id'=>'tendency_c','style'=>'width:80px;'))?>
              </li>
              <li><span class="left"><strong>学&nbsp;&nbsp;&nbsp;&nbsp;历：</strong></span>
                <?php echo $form->dropDownList($user,'edu',User::getDegree());?>
              </li>
              <li><span class="left"><strong>择友学历：</strong></span>
               <?php echo $form->dropDownList($setting,'edu_tendency',User::getDegree());?>
               <span class="left">以上</span> </li>
               <li><span class="left"><strong>收&nbsp;&nbsp;&nbsp;&nbsp;入：</strong></span>
                <?php echo $form->dropDownList($user,'income', User::getIncome())?>
              </li>
              <li><span class="left"><strong>择友收入：</strong></span>
                <?php echo $form->dropDownList($setting,'income_tendency', User::getIncome())?>
                <span class="left">以上</span> </li>
                <li><span class="left"><strong>身&nbsp;&nbsp;&nbsp;&nbsp;高：</strong></span>
                  <?php echo $form->dropDownList($user, 'height', array_combine(range(130, 210),range(130, 210)));?><span class="left">cm</span> 
                </li>
                <li><span class="left"><strong>择友身高：</strong></span>
                 <?php echo $form->dropDownList($setting, 'height_start', Utils::genHeightSelect());?>
                 <span class="left" style="margin-right:10px;">~</span>
                 <?php echo $form->dropDownList($setting, 'height_end', Utils::genHeightSelect());?>
               </li>
             </ul>
           </div>
           <div class="base_infor_modify"><span onclick="$('#user-regist').submit();">保存</span></div>
         </div>
       </div>
     </div>
   </div>
 </div> 
 <?php $this->endWidget();?>
<script type="text/javascript">
 if($.cookie('tmp_email')){
  $('#User_email').val($.cookie('tmp_email'));$.cookie('tmp_email','');
}
 if($.cookie('tmp_password')){
  $('#User_password').val($.cookie('tmp_password'));$.cookie('tmp_password','');
}
</script>

<script>
var ds = new DateSelector("idYear", "idMonth", "idDay", {
  MaxYear: new Date().getFullYear()-18,
  MinYear: new Date().getFullYear() -50,
  onChange: function(){
    var m=this.Month;
    var d=this.Day;
  if(m<10)var m='0'+m; 
  if(d<10)var d='0'+d; 
    $("#idShow").val(this.Year + "-" + m + "-" + d); }
});

ds.onChange();

$(document).ready(function(){
  setInterval(function(){
    var act = document.activeElement.id;
    if($('#User_email_em_').css('display')=='none' && act!='User_email'&& $('#User_email').val()){
    $('#zee_email').show();
  }else{
    $('#zee_email').hide();
  }
  },1000);

  setInterval(function(){
    var act = document.activeElement.id;
    if($('#User_nickname_em_').css('display')=='none' && act!='User_nickname'&& $('#User_nickname').val()){
    $('#zee_nick').show();
  }else{
    $('#zee_nick').hide();
  }
  },1000);


  setInterval(function(){
    var act = document.activeElement.id;
    if($('#User_password_tmp_em_').css('display')=='none' && act!='User_password_tmp' && $('#User_password_tmp').val()){
    $('#zee_pwd').show();
  }else{
    $('#zee_pwd').hide();
  }
  },1000);

  setInterval(function(){
    var act = document.activeElement.id;
    if($('#User_subdomain_em_').css('display')=='none' && act!='User_subdomain' && $('#User_subdomain').val()){
    $('#zee_sub').show();
  }else{
    $('#zee_sub').hide();
  }
  },1000);
  });
  
</script>